﻿/********************************************************************************
 * This code is provided as-is, with no explicit or implicit guaranties         *
 * and is governed by the Common Creative License.                              *
 *                                                                              *
 * If you find this code useful and decide to use it for your                   *
 * own proyects, please be sure to copy this complete header, along             *
 * with the authors name.                                                       *
 *                                                                              *
 * A link back from your personal site to the articles URL                      *
 * will also be appreciated                                                     *
 *                                                                              *
 * @author: Matthias Reichenbach                                                *
 * (http://www.codeproject.com/script/Membership/Profiles.aspx?mid=3576642)     *
 *                                                                              *
 * ******************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace FuzzyLogic
{
    class Player
    {
        public PointF posRobot;
        public double angRobot;

        public Player(int w, int h,Random r)
        {
            posRobot.X = r.Next(w);
            posRobot.Y = r.Next(h);
        }

        public double getAngulo(PointF posPelota)
        {
            double res = 180 * (Math.PI / 2 - angRobot + this.getATan(posPelota)) / Math.PI;
            if (0 <= res && res <= 2 * 360)
                return res;
            else if (res < 0)
                return res + 360;
            else
                return res - 360;
        }

        public double getDistancia(PointF posPelota)
        {
            return Math.Sqrt(Math.Pow(posPelota.Y - posRobot.Y, 2) + Math.Pow(posPelota.X - posRobot.X, 2)) * Math.Sin(angRobot - this.getATan(posPelota));
        }

        private double getATan(PointF posPelota)
        {
            if ((posPelota.X - posRobot.X) >= 0)// || true)
                return Math.Atan((posPelota.Y - posRobot.Y) / (posPelota.X - posRobot.X));
            else
                return Math.PI + Math.Atan((posPelota.Y - posRobot.Y) / (posPelota.X - posRobot.X));
        }
    }
}
